package com.Tool;

import java.io.Serializable;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;

public class DatabaseControler {

	public  Configuration conf=new Configuration().configure();
	public  SessionFactory sf=conf.buildSessionFactory();
	public  Session hibernateSess=sf.openSession();
	public  Transaction tx = hibernateSess.beginTransaction();

	public  Serializable save(Object target){
		return hibernateSess.save(target);
	}
	public void commit(){
		tx.commit();
		this.conf=new Configuration().configure();
		this.sf=conf.buildSessionFactory();
		this.hibernateSess=sf.openSession();
		this.tx = hibernateSess.beginTransaction();
	}
	public Object load(Class arg0, Serializable arg1){
		return hibernateSess.load(arg0, arg1);
	}
	public void finnalize() throws Throwable{
		hibernateSess.close();
		super.finalize();
	}
}
